package com.gxa.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.R;
import com.gxa.common.vo.AttendancePageRequest;
import com.gxa.common.vo.AttendanceVo;
import com.gxa.common.vo.AttendanceWeeklyReportVo;
import com.gxa.common.vo.SysUserVo;
import com.gxa.entity.AttendanceClock;
import com.gxa.mapper.AttendanceWeeklyReportMapper;
import com.gxa.mapper.AttendenceMapper;
import com.gxa.service.AttendanceWeeklyReportService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class AttendanceWeeklyReportServiceImpl implements AttendanceWeeklyReportService {

    @Autowired
    AttendanceWeeklyReportMapper mapper;

    /**
     * 考勤周报表显示
     * @param attendancePageRequest
     * @return
     */
    @Override
    public R showWeekList(AttendancePageRequest attendancePageRequest) {
        R r = new R<>();
        Integer currentPage = attendancePageRequest.getPageNum();
        Integer pageSize = attendancePageRequest.getPageSize();
        String startTime = attendancePageRequest.getStartTime();
        String endTime = attendancePageRequest.getEndTime();

        PageHelper.startPage(currentPage,pageSize);
        List<SysUserVo> userVoList = mapper.findUsernameAndDepName();
        for (SysUserVo s:userVoList){
            Integer userId = s.getUserId();
            List<AttendanceVo> list = mapper.findUserAttendanceByUserId(startTime,endTime,userId);
            s.setAttendanceVoList(list);
        }
        PageInfo<AttendanceClock> pageInfo = new PageInfo(userVoList);
        r.setCode(200);
        r.setMsg("success");
        r.setData(pageInfo);

        return r;
    }
}
